package asteroids;

import geometry.Geometry;


import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Sprite;

public class Bullet extends AsteroidsComponent{
	
	final double SPEED = 20;
	final int LIFETIME = 20;
	
	int counter = 0;
	
	public Bullet(Ship ship) {
		super(ship.getX(),ship.getY());
		this.setAppearance(Sprite.fromImage("/images/laser.png"));
		this.setVector(Geometry.polar(this.SPEED,ship.getO()));
	}
	
	
	@Override
	public void update(DeltaState deltaState) {
		double advanced = this.SPEED * deltaState.getDelta();
		this.move(advanced*this.getVector().getX(),advanced*this.getVector().getY());
		if(this.collidesAgainstAsteroid() || this.counter == this.LIFETIME){
			this.destroy();			
		}else{
			this.counter++;
			this.checkScreenLimits();
		}		
		super.update(deltaState);
	}

}
